home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
SPACE 1
/
SPACE - Library 1 - Volume 1.iso
/
program
/
386
/
algrtest
/
clr_mem.s
< prev
next >
Wrap
Text File
|
1985-11-19
|
7KB
|
164 lines
; Program Name: CLR_MEM.S
; Version: 1.005
; Assembly Instructions:
; Assemble in PC-relative mode save with a TOS extension.
; Execution Instructions:
; Execute from the desktop; or execute SPAWN.TTP, type CLR_MEM.TOS on
; its command line and view this program's output in CLR_MEM.DAT.
; Program Function:
; Expands the concepts established with program PUSHZERO. Here,
; simulating the type of algorithm that would be used to clear video screen
; memory, the execution time when clearing memory a longword each time,
; within a loop, is compared to that of the more obvious method of clearing
; a byte, or perhaps a word, each time through the loop.
; Then, the speed advantage of clearing a longword by storing the
; content of a cleared register is illustrated.
; Finally, the advantage of clearing more than one longword within the
; body of the loop is explored, with an eye out for the maximum amount of
; beneficial loop expansion.
calculate_program_size:
lea -$102(pc), a1 ; Fetch basepage start address.
lea array, a0 ; Fetch program end = array address.
adda.l #32000, a0 ; Add in array space.
movea.l a0, a7 ; Point A7 to this program's stack.
trap #6 ; Return unused memory to op system.
print_heading:
lea heading, a0
bsr print_string
clear_one_byte_algorithm:
lea header_1, a0
bsr print_string
lea array, a0 ; A0 is pointer to 32000 byte array.
move.l #31999, d7 ; D7 is counter for the clear loop.
trap #3 ; Fetch start time.
move.l d0, d3 ; Save start_time in D3.
clear_a_byte:
move.b #0, (a0)+
dbra d7, clear_a_byte ; Loop 32000 times.
trap #3 ; Fetch end time.
sub.l d3, d0 ; Subtract start time from end time.
trap #10 ; Convert to decimal milliseconds and print.
clear_one_word_algorithm:
lea header_2, a0
bsr print_string
lea array, a0 ; A0 is pointer to 32000 byte array.
move.l #15999, d7 ; D7 is counter for the clear loop.
trap #3 ; Fetch start time.
move.l d0, d3 ; Save start_time in D3.
clear_a_word:
move.w #0, (a0)+
dbra d7, clear_a_word ; Loop 16000 times.
trap #3 ; Fetch end time.
sub.l d3, d0 ; Subtract start time from end time.
trap #10 ; Convert to decimal milliseconds and print.
clear_one_longword_algorithm:
lea header_3, a0
bsr print_string
lea array, a0
move.l #7999, d7
trap #3 ; Fetch start time.
move.l d0, d3 ; Save start_time in D3.
clear_a_longword:
move.l #0, (a0)+
dbra d7, clear_a_longword; Loop 8000 times.
trap #3 ; Fetch end time.
sub.l d3, d0 ; Subtract start time from end time.
trap #10 ; Convert to decimal milliseconds and print.
clear_one_longword_with_precleared_register:
lea header_4, a0
bsr print_string
lea array, a0
moveq #0, d1 ; Preclear D1 for use in the loop.
move.l #7999, d7
trap #3 ; Fetch start time.
move.l d0, d3 ; Save start_time in D3.
clear_with_register:
move.l d1, (a0)+ ; Clear a longword.
dbra d7, clear_with_register
trap #3 ; Fetch end time.
sub.l d3, d0 ; Subtract start time from end time.
trap #10 ; Convert to decimal milliseconds and print.
clear_4_longwords_algorithm:
lea header_5, a0
bsr.s print_string
lea array, a0
move.l #0, d1 ; Preclear D1 for use in the loop.
move.l #1999, d7
trap #3 ; Fetch start time.
move.l d0, d3 ; Save start_time in D3.
clr_4_longwords:
move.l d1, (a0)+ ; A single move statement clears 4 bytes.
move.l d1, (a0)+ ; Reduces number of loops to 4000.
move.l d1, (a0)+ ; Reduces number of loops to 2666+.
move.l d1, (a0)+ ; Reduces number of loops to 2000.
dbra d7, clr_4_longwords ; Loop 2000 times, clear 16 bytes each time.
trap #3 ; Fetch end time.
sub.l d3, d0 ; Subtract start time from end time.
trap #10 ; Convert to decimal milliseconds and print.
clear_8_longwords_algorithm: ; Will a further increase in move instructions
lea header_6, a0 ; within the loop decrease execution time?
bsr.s print_string
lea array, a0
move.l #0, d1 ; Preclear D1 for use in the loop.
move.l #999, d7
trap #3 ; Fetch start time.
move.l d0, d3 ; Save start_time in D3.
clr_8_longwords:
move.l d1, (a0)+ ; A single move statement clears 4 bytes.
move.l d1, (a0)+ ; Reduces number of loops to 4000.
move.l d1, (a0)+ ; Reduces number of loops to 2666+.
move.l d1, (a0)+ ; Reduces number of loops to 2000.
move.l d1, (a0)+ ; Reduces number of loops to 1600.
move.l d1, (a0)+ ; Reduces number of loops to 1333+.
move.l d1, (a0)+ ; Reduces number of loops to 1142+.
move.l d1, (a0)+ ; Reduces number of loops to 1000.
dbra d7, clr_8_longwords ; Loop 1000 times, clear 32 bytes each time.
trap #3 ; Fetch end time.
sub.l d3, d0 ; Subtract start time from end time.
trap #10 ; Convert to decimal milliseconds and print.
terminate:
trap #8
;
; SUBROUTINES
;
print_string: ; Expects address of string to be in A0.
move.l a0, -(sp) ; Push address of string onto stack.
move.w #9, -(sp) ; Function = c_conws = GEMDOS $9.
trap #1 ; GEMDOS call
addq.l #6, sp ; Reset stack pointer to top of stack.
rts
data
heading: dc.b 'CLR_MEM Execution Results',$D,$A,0
header_1: dc.b ' Clear one byte time: ',0
header_2: dc.b ' Clear one word time: ',0
header_3: dc.b ' Clear one longword time: ',0
header_4: dc.b ' With register time: ',0
header_5: dc.b ' Clear 4 longwords time: ',0
header_6: dc.b ' Clear 8 longwords time: ',0
bss
align
ds.l 96 ; Stack.
stack: ds.l 1 ; Address of stack.
array: ds.l 0
end